package com.ego.item.controller;

import com.ego.item.pojo.Specification;
import com.ego.item.service.SpecificationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/spec")
public class SpecificationController {

    @Resource
    private SpecificationService specificationService;

    @GetMapping("/{cid}")
    public ResponseEntity<String> find(@PathVariable("cid") Long cid){
        return ResponseEntity.ok(specificationService.findSpec(cid).getSpecifications());
    }

    @PostMapping
    public ResponseEntity<Void> save(Specification specification){
        specificationService.insert(specification);
        return ResponseEntity.ok().build();
    }

    @PutMapping
    public ResponseEntity<Void> update(Specification specification){
        specificationService.update(specification);
        return ResponseEntity.ok().build();
    }
}
